<?php
    // +----------------------------------------------------------------------
    // | 海豚PHP框架 [ DolphinPHP ]
    // +----------------------------------------------------------------------
    // | 版权所有 2016~2017 河源市卓锐科技有限公司 [ http://www.zrthink.com ]
    // +----------------------------------------------------------------------
    // | 官方网站: http://dolphinphp.com
    // +----------------------------------------------------------------------
    // | 开源协议 ( http://www.apache.org/licenses/LICENSE-2.0 )
    // +----------------------------------------------------------------------

    namespace app\payment\validate;

    use app\payment\model\PaymentWithdrawModel;
    use think\Validate;

    /**
     * Class Withdrawratio
     *
     * @package app\payment\validate
     */
    class Withdrawratio extends Validate
    {

        // 定义验证规则
        protected $rule = [
            'status|审核状态'         => 'require|number|in:1,2',
            'admin_remarks|审核说明！' => 'require',
            'order_sn|订单编号！'      => 'require|number|check_order_sn',
        ];

        // 定义验证提示
        protected $message = [
            'money.min' => '提现金额不得小于100',
            'type.in'   => '提现只能是支付宝微信或者银行卡',
        ];

        // 定义验证场景
        protected $scene = [
            'check' => ['status','admin_remarks'],
        ];

        /**
         * 检查订单是否存在
         *
         * @param $rule
         * @param $value
         * @param $data
         *
         * @return bool|string
         * @throws \think\db\exception\DataNotFoundException
         * @throws \think\db\exception\ModelNotFoundException
         * @throws \think\exception\DbException
         */
        protected function check_order_sn($rule,$value,$data)
        {

            return PaymentWithdrawModel::where(['order_sn' => $data['order_sn']])->find() ? true : '订单不存在！';

        }
    }
